
package com.zainaer.adapter;

import android.content.Context;

import android.net.Uri;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import java.io.File;
import java.util.List;

import com.zainaer.R;


public class ChatListAdapter extends BaseAdapter {
    private List<String> coll;
	private LayoutInflater mLauoutInflater;

    public ChatListAdapter(Context context, List<String> coll) {
		this.mLauoutInflater = LayoutInflater.from(context);
        this.coll = coll;
    }
    
    public int getCount() {
        return coll.size();
    }

    public Object getItem(int position) {
        return coll.get(position);
    }

    public long getItemId(int position) {
        return position;
    }

    public int getItemViewType(int position) {
        return position;
    }

    public View getView(int position, View convertView, ViewGroup parent) {
    	RecentViewHolder holder;
		if (convertView == null) {
			holder = new RecentViewHolder();
			convertView = mLauoutInflater.inflate(R.layout.chatlist_item,
					null);
			holder.name = (TextView) convertView.findViewById(R.id.chatlistitem_name);
			holder.content = (TextView) convertView.findViewById(R.id.chatlistitem_content);
			holder.time = (TextView) convertView.findViewById(R.id.chatlistitem_time);
			holder.status = (TextView) convertView.findViewById(R.id.chatlistitem_status);		
			holder.image = (ImageView) convertView.findViewById(R.id.chatlistitem_icon);	
			holder.tip = (TextView) convertView.findViewById(R.id.chatlistitem_tip);	
			convertView.setTag(holder);
			
			holder.name.setText("俊西" + position);
			holder.content.setText(coll.get(position));
			holder.time.setText("昨天 12:00:00");
			holder.status.setText("[已发送]");
			holder.image.setImageURI(Uri.fromFile(new File("/mnt/sdcard/Tencent/MobileQQ/head/hd/1149073009.png")));
			holder.tip.setText("" + position);
		} else {
			holder = (RecentViewHolder) convertView.getTag();
		}

		return convertView;

    }

    public int getViewTypeCount() {
        return coll.size();
    }
 
    public boolean hasStableIds() {
        return false;
    }

    public boolean isEmpty() {
        return false;
    }
    
    public void remove(int position){
    	coll.remove(position);
    	this.notifyDataSetChanged();
    }

    private class RecentViewHolder {
//    	名字
    	TextView name;
//    	头像
    	ImageView image;
//    	最新消息
    	TextView content;
//    	时间
    	TextView time;
//    	消息状态
    	TextView status;
//    	新消息提示
    	TextView tip;
    }


}
